<template>
  <header class="header">
    <div class="container">
      <div class="logo">
        <router-link to="/">余承东 | 个人简历</router-link>
      </div>
      
      <button class="menu-toggle" @click="toggleMenu" aria-label="Toggle menu">
        <span></span>
        <span></span>
        <span></span>
      </button>
      
      <nav class="nav" :class="{ 'is-active': isMenuOpen }">
        <ul class="nav-list">
          <li v-for="item in menuItems" :key="item.path">
            <router-link :to="item.path" @click="isMenuOpen = false">
              {{ item.name }}
            </router-link>
          </li>
        </ul>
      </nav>
    </div>
  </header>
</template>

<script setup>
import { ref } from 'vue'

const isMenuOpen = ref(false)

const menuItems = [
  { name: '首页', path: '/' },
  { name: '职业经历', path: '/experience' },
  { name: '荣誉成就', path: '/honors' },
  { name: '社会活动', path: '/activities' },
  { name: '职务任免', path: '/positions' },
  { name: 'AI问答', path: '/aichat' }
]

function toggleMenu() {
  isMenuOpen.value = !isMenuOpen.value
}
</script>

<style scoped>
.header {
  background-color: #ffffff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 2rem;
}

.logo a {
  text-decoration: none;
  font-size: 1.25rem;
  font-weight: 700;
  color: #1a1a1a;
}

.nav-list {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 1.5rem;
}

.nav-list a {
  text-decoration: none;
  color: #4a4a4a;
  font-weight: 500;
  padding: 0.5rem 0;
  position: relative;
  transition: color 0.3s;
}

.nav-list a:hover {
  color: #007bff;
}

.nav-list a.router-link-active {
  color: #007bff;
}

.nav-list a.router-link-active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 2px;
  background-color: #007bff;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
}

.menu-toggle span {
  display: block;
  width: 24px;
  height: 3px;
  background-color: #333;
  margin: 5px 0;
  transition: all 0.3s;
}

@media (max-width: 768px) {
  .menu-toggle {
    display: block;
  }
  
  .nav {
    position: fixed;
    top: 70px;
    left: 0;
    width: 100%;
    height: 0;
    background-color: #ffffff;
    overflow: hidden;
    transition: height 0.3s ease-in-out;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
  }
  
  .nav.is-active {
    height: auto;
  }
  
  .nav-list {
    flex-direction: column;
    padding: 1rem;
    gap: 0;
  }
  
  .nav-list li {
    width: 100%;
  }
  
  .nav-list a {
    display: block;
    padding: 1rem 0;
    border-bottom: 1px solid #eaeaea;
  }
  
  .menu-toggle.active span:first-child {
    transform: rotate(45deg) translate(5px, 5px);
  }
  
  .menu-toggle.active span:nth-child(2) {
    opacity: 0;
  }
  
  .menu-toggle.active span:last-child {
    transform: rotate(-45deg) translate(5px, -5px);
  }
}
</style>
